<template>
	<view>
		<view v-if="isShowLogin" class="uni-padding-wrap uni-common-mt">
			<view class="button-sp-area">
				<button type="primary" plain="true" @click="mylogin()">登录</button>
			</view>
		</view>
		<view v-if="isShowLogOut" class="uni-padding-wrap uni-common-mt">
			<view class="button-sp-area">
				<button type="primary" plain="true" @click="mylogout()">退出</button>
			</view>
		</view>
	</view>
</template>

<script>
	import loginservice from '../../myservice/loginservice.js'
	import commonservice from '../../myservice/commonservice.js'
	import {mapState,mapMutations} from 'vuex'
	
	export default {
		data() {
			return {
				isShowLogin: true,//是否展示登录按钮
				isShowLogOut:false //是否展示退出按钮
			}
		},computed: {
			...mapState(['hasLogin', 'gotoinfo']),
		},
		methods: {
			//绑定
			...mapMutations(['logout','setGotoInfo']), //方法设置登录
			mylogin() {
				console.log("12133");
				uni.navigateTo({
					url: '../login/login'
				});
			},
			mylogout(){
				this.logout();
				uni.navigateTo({
					url:'../login/login'
				})
				// loginservice.LogOut().then(res=>{
				// 	console.log(JSON.stringify(res));
				// 	commonservice.AccessToken='';
				// 	uni.navigateTo({
				// 		url:'../login/login'
				// 	})
				// })
			}
		},
		onShow() {
			var that=this;
			//根据accesstoken判断有没有登录状态，如果已登录则展示退出按钮
			if(this.hasLogin){
				that.isShowLogin=false;
				that.isShowLogOut=true;
			}else{
				that.isShowLogin=true;
				that.isShowLogOut=false;
			}
		},
		onLoad() {
			if(!this.hasLogin){
				this.setGotoInfo();
				uni.navigateTo({
					url:'../login/login'
				})
			}
		}
	}
</script>

<style>
</style>
